/**
 * @file   RegistrationRequestPacket.h
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2014-04-21
 * @brief  DON packet object: Registration Request
 *
 * Copyright 2014  Djuro Drljaca (djurodrljaca@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DON_CORE_PACKET_REGISTRATIONREQUESTPACKET_H
#define DON_CORE_PACKET_REGISTRATIONREQUESTPACKET_H

#include <DON/Core/Packet/AbstractPacket.h>
#include <DON/Core/Node/CommunicationMode.h>

namespace DON
{
namespace Core
{
namespace Packet
{

class GenericPacket;

/**
 * @brief The RegistrationRequestPacket class
 */
class LIBDONQT4CORESHARED_EXPORT RegistrationRequestPacket : public AbstractPacket
{
public:
    /**
     * @brief Constructor
     */
    RegistrationRequestPacket();

    /**
     * @brief Constructor
     * @param source Packet's Source address
     * @param destination Packet's Destination address
     * @param sequence Sequence number
     * @param addressCount Number of addresses reserved by the node
     * @param communicationMode Node's communication mode
     * @param maxPayloadLength Maximum payload length in bytes
     */
    RegistrationRequestPacket(const quint16 source,
                              const quint16 destination,
                              const quint16 sequence,
                              const quint16 addressCount,
                              const Node::CommunicationMode communicationMode,
                              const quint16 maxPayloadLength);

    /**
     * @brief Copy constructor
     * @param other Object to be copied
     */
    RegistrationRequestPacket(const RegistrationRequestPacket &other);

    /**
     * @brief Destructor
     */
    ~RegistrationRequestPacket();

    /**
     * @brief Assignment operator
     * @param other Object to be copied
     * @return This object
     */
    RegistrationRequestPacket & operator=(const RegistrationRequestPacket &other);

    /**
     * @brief Checks if packet is valid
     * @retval true Packet is valid
     * @retval false Packet is not valid
     */
    bool isValid() const;

    /**
     * @brief Get address count
     * @return Address count
     */
    quint16 getAddressCount() const;

    /**
     * @brief Set address count
     * @param addressCount New address count
     */
    void setAddressCount(const quint16 addressCount);

    /**
     * @brief Get communication mode
     * @return Communication mode
     */
    Node::CommunicationMode getCommunicationMode() const;

    /**
     * @brief Set communication mode
     * @param communicationMode New communication mode
     */
    void setCommunicationMode(const Node::CommunicationMode communicationMode);

    /**
     * @brief Get maximum payload length
     * @return Maximum payload length
     */
    quint16 getMaxPayloadLength() const;

    /**
     * @brief Set maximum payload length
     * @param maxPayloadLength New maximum payload length
     */
    void setMaxPayloadLength(const quint16 maxPayloadLength);

    /**
     * @brief Create RegistrationRequestPacket from a GenericPacket
     * @param genericPacket Generic packet
     * @return RegistrationRequestPacket
     */
    static RegistrationRequestPacket fromGenericPacket(const GenericPacket &genericPacket);

private:
    /**
     * @brief Get the packet's payload data items
     * @param[out] ok Error status output (true --> success, false --> error)
     * @return List of payload data items
     */
    QList<QByteArray> getPayloadDataItems(bool *ok = NULL) const;

    class Private;
    Private * const d;
};

}
}
}

#endif // DON_CORE_PACKET_REGISTRATIONREQUESTPACKET_H
